//
//  ReportProjectDetail2Cell.m
//  efairy
//
//  Created by 李锋 on 2019/3/19.
//  Copyright © 2019年 East. All rights reserved.
//

#import "ReportProjectDetail2Cell.h"

@implementation ReportProjectDetail2Cell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        [self initView];
    }
    return self;
}

-(void)initView{
    _statisticsTitle = [[UIView alloc]init];
    _statisticsTitle.backgroundColor = ColorFromRGB(0xf9f9fb);
    [self.contentView addSubview:_statisticsTitle];
    _statisticsTitle.sd_layout.topSpaceToView(self.contentView, 0).leftSpaceToView(self.contentView, 16).rightSpaceToView(self.contentView, 16).heightIs(34);
    UILabel *type = [[UILabel alloc]init];
    type.text = @"设备类型";
    type.textColor = ColorFromRGB(0x333333);
    type.font = [UIFont systemFontOfSize:12.f];
    type.textAlignment = NSTextAlignmentCenter;
    
    UILabel *point = [[UILabel alloc]init];
    point.text = @"点位";
    point.textColor = ColorFromRGB(0x333333);
    point.font = [UIFont systemFontOfSize:12.f];
    point.textAlignment = NSTextAlignmentCenter;
    
    UILabel *alarm = [[UILabel alloc]init];
    alarm.text = @"报警";
    alarm.textColor = ColorFromRGB(0x333333);
    alarm.font = [UIFont systemFontOfSize:12.f];
    alarm.textAlignment = NSTextAlignmentCenter;
    
    UILabel *warning = [[UILabel alloc]init];
    warning.text = @"预警";
    warning.textColor = ColorFromRGB(0x333333);
    warning.font = [UIFont systemFontOfSize:12.f];
    warning.textAlignment = NSTextAlignmentCenter;
    
    UILabel *trouble = [[UILabel alloc]init];
    trouble.text = @"故障";
    trouble.textColor = ColorFromRGB(0x333333);
    trouble.font = [UIFont systemFontOfSize:12.f];
    trouble.textAlignment = NSTextAlignmentCenter;
    [_statisticsTitle sd_addSubviews:@[type,point,alarm,warning,trouble]];
    
    trouble.sd_layout.widthIs(48).heightIs(34).rightSpaceToView(_statisticsTitle, 0);
    warning.sd_layout.widthIs(48).heightIs(34).rightSpaceToView(trouble, 0);
    alarm.sd_layout.widthIs(48).heightIs(34).rightSpaceToView(warning, 0);
    point.sd_layout.widthIs(48).heightIs(34).rightSpaceToView(alarm, 0);
    type.sd_layout.heightIs(34).leftSpaceToView(_statisticsTitle, 0).rightSpaceToView(point, 1);
   
   
}

-(void)setDataModel:(DeviceStatistics *)data{
    if(data && data.device_statistics_list.count > 0){
        for (int i = 0; i< data.device_statistics_list.count; i++) {
            UIView *statistics = [[UIView alloc]initWithFrame:CGRectMake(16, _statisticsTitle.frame.origin.y+34+i*44, SCREEN_WIDTH-32, 44)];
            statistics.backgroundColor = ColorFromRGB(0xf2f2f4);
            [self.contentView addSubview:statistics];


            UIView *line = [[UIView alloc]init];
            line.backgroundColor = ColorFromRGB(0xe5e5e5);

            UILabel *type = [[UILabel alloc]init];
            type.text =data.device_statistics_list[i].efairydevice_device_type;
            type.textColor = ColorFromRGB(0x999999);
            type.font = [UIFont systemFontOfSize:12.f];
            type.textAlignment = NSTextAlignmentLeft;

            UILabel *point = [[UILabel alloc]init];
            point.text = data.device_statistics_list[i].total_devices;
            point.textColor = ColorFromRGB(0x999999);
            point.font = [UIFont systemFontOfSize:12.f];
            point.textAlignment = NSTextAlignmentCenter;

            UILabel *alarm = [[UILabel alloc]init];
            alarm.text = data.device_statistics_list[i].total_alarm_devices;
            alarm.textColor = ColorFromRGB(0xFF0000);
            alarm.font = [UIFont systemFontOfSize:12.f];
            alarm.textAlignment = NSTextAlignmentCenter;

            UILabel *warning = [[UILabel alloc]init];
            warning.text = data.device_statistics_list[i].total_early_warning_devices;
            warning.textColor = ColorFromRGB(0xFF7200);
            warning.font = [UIFont systemFontOfSize:12.f];
            warning.textAlignment = NSTextAlignmentCenter;

            UILabel *trouble = [[UILabel alloc]init];
            trouble.text = data.device_statistics_list[i].total_trouble_devices;
            trouble.textColor = ColorFromRGB(0xFFB900);
            trouble.font = [UIFont systemFontOfSize:12.f];
            trouble.textAlignment = NSTextAlignmentCenter;
            [statistics sd_addSubviews:@[type,point,alarm,warning,trouble,line]];

            trouble.sd_layout.widthIs(48).heightIs(44).rightSpaceToView(statistics, 0);
            warning.sd_layout.widthIs(48).heightIs(44).rightSpaceToView(trouble, 0);
            alarm.sd_layout.widthIs(48).heightIs(44).rightSpaceToView(warning, 0);
            point.sd_layout.widthIs(48).heightIs(44).rightSpaceToView(alarm, 0);
            type.sd_layout.leftSpaceToView(statistics, 2).rightSpaceToView(point, 1).autoHeightRatio(0).minHeightIs(44).maxHeightIs(44);
            line.sd_layout.topSpaceToView(statistics,0).leftSpaceToView(statistics, 0).rightSpaceToView(statistics, 0).heightIs(1);

            if(i == data.device_statistics_list.count-1){
                _dividingLine = [[UIView alloc]initWithFrame:CGRectMake(0, statistics.frame.origin.y+44+12, SCREEN_WIDTH, 1)];
                _dividingLine.backgroundColor = ColorFromRGB(0xe5e5e5);
                [self.contentView addSubview:_dividingLine];
            }

        }
    }else{
        _dividingLine = [[UIView alloc]initWithFrame:CGRectMake(0, _statisticsTitle.frame.origin.y+34+12, SCREEN_WIDTH, 1)];
        _dividingLine.backgroundColor = ColorFromRGB(0xe5e5e5);
        [self.contentView addSubview:_dividingLine];
    }
    
  
    _reportChart = [[UIButton alloc]initWithFrame:CGRectMake(0, _dividingLine.frame.origin.y, SCREEN_WIDTH/2,  44)];
    [_reportChart setTitle:@"报警统计表" forState:UIControlStateNormal];
    _reportChart.titleLabel.font = [UIFont systemFontOfSize:15.0f];
    [_reportChart setTitleColor:ColorFromRGB(0x282449) forState:UIControlStateNormal];
    [_reportChart addTarget:self action:@selector(onClickChartBtn) forControlEvents:UIControlEventTouchUpInside];


    _reportPointList =  [[UIButton alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2, _dividingLine.frame.origin.y, SCREEN_WIDTH/2,  44)];
    [_reportPointList setTitle:@"报警/预警/故障点位" forState:UIControlStateNormal];
    _reportPointList.titleLabel.font = [UIFont systemFontOfSize:15.0f];
    [_reportPointList setTitleColor:ColorFromRGB(0x666666) forState:UIControlStateNormal];
    [_reportPointList addTarget:self action:@selector(onClickPointBtn) forControlEvents:UIControlEventTouchUpInside];

    _reportChartLine = [[UIView alloc]initWithFrame:CGRectMake((SCREEN_WIDTH/2-60)/2, _reportChart.frame.origin.y+43, 60, 2)];
    _reportChartLine.backgroundColor = ColorFromRGB(0x282449);
    _reportPointListLine = [[UIView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2+(SCREEN_WIDTH/2-60)/2, _reportChart.frame.origin.y+43, 60, 2)];
    _reportPointListLine.backgroundColor = ColorFromRGB(0x282449);
   
    if(_isChooseReportChartBtn){
        [_reportChart setTitleColor:ColorFromRGB(0x282449) forState:UIControlStateNormal];
        [_reportPointList setTitleColor:ColorFromRGB(0x666666) forState:UIControlStateNormal];
        _reportChartLine.hidden = NO;
        _reportPointListLine.hidden = YES;
    }else{
        [_reportChart setTitleColor:ColorFromRGB(0x666666) forState:UIControlStateNormal];
        [_reportPointList setTitleColor:ColorFromRGB(0x282449) forState:UIControlStateNormal];
        _reportChartLine.hidden = YES;
        _reportPointListLine.hidden = NO;
    }
    [self.contentView sd_addSubviews:@[_reportChart,_reportPointList,_reportChartLine,_reportPointListLine]];
    [self setupAutoHeightWithBottomView:_reportPointList bottomMargin:0];
}

-(void)onClickChartBtn{
    if(self.chooseChartReport){
        [_reportChart setTitleColor:ColorFromRGB(0x282449) forState:UIControlStateNormal];
        [_reportPointList setTitleColor:ColorFromRGB(0x666666) forState:UIControlStateNormal];
        _reportChartLine.hidden = NO;
        _reportPointListLine.hidden = YES;
        self.chooseChartReport();
    }
   
}

-(void)onClickPointBtn{
    if(self.chooseAlarmListReport){
        [_reportChart setTitleColor:ColorFromRGB(0x666666) forState:UIControlStateNormal];
        [_reportPointList setTitleColor:ColorFromRGB(0x282449) forState:UIControlStateNormal];
        _reportChartLine.hidden = YES;
        _reportPointListLine.hidden = NO;
         self.chooseAlarmListReport();
    }
}
@end

